<?php
defined('_JEXEC') or die( 'Restricted access' );
class HamhaydungLibs
{
	
	function cutchuoi($string,$len)
	{
		if($len > strlen($string)){$len=strlen($string);};
		$pos = strpos($string, ' ', $len);
		if($pos){$string = substr($string,0,$pos);}else{$string = substr($string,0,$len);}    
		return $string;
	}
		
	function pagenav($base_url, $start, $max_value, $num_per_page)
	{
		$pgcont = 10;
		$pgcont = (int) ($pgcont - ($pgcont % 2)) / 2;
		if ($start >= $max_value)
			$start = max(0, (int) $max_value - (((int) $max_value % (int)  $num_per_page) == 0 ? $num_per_page : ((int) $max_value % (int)  $num_per_page)));
		else
			$start = max(0, (int) $start - ((int) $start % (int) $num_per_page));
		$base_link = '<a class="navpg" href="' . strtr($base_url, array('%' => '%%')) . 'start=%d' . '">%s</a> ';
		$pageindex = $start == 0 ? '' : sprintf($base_link, $start - $num_per_page, '&lt;&lt;');
		if ($start > $num_per_page * $pgcont)
			$pageindex .= sprintf($base_link, 0, '1');
		if ($start > $num_per_page * ($pgcont + 1))
			$pageindex .= '<span style="font-weight: bold;"> ... </span>';
		for ($nCont = $pgcont; $nCont >= 1; $nCont--)
			if ($start >= $num_per_page * $nCont) {
				$tmpStart = $start - $num_per_page * $nCont;
				$pageindex .= sprintf($base_link, $tmpStart, $tmpStart / $num_per_page + 1);
			}
			// $pageindex .= '[<b>' . ($start / $num_per_page + 1) . '</b>] ';
			$pageindex .= '<a class="active" href="javascript:void(0)" >' . ($start / $num_per_page + 1) . '</a>';
		$tmpMaxPages = (int) (($max_value - 1) / $num_per_page) * $num_per_page;
		for ($nCont = 1; $nCont <= $pgcont; $nCont++)
			if ($start + $num_per_page * $nCont <= $tmpMaxPages) {
				$tmpStart = $start + $num_per_page * $nCont;
				$pageindex .= sprintf($base_link, $tmpStart, $tmpStart / $num_per_page + 1);
			}
			if ($start + $num_per_page * ($pgcont + 1) < $tmpMaxPages)
				$pageindex .= '<span style="font-weight: bold;"> ... </span>';
			if ($start + $num_per_page * $pgcont < $tmpMaxPages)
				$pageindex .= sprintf($base_link, $tmpMaxPages, $tmpMaxPages / $num_per_page + 1);
				
			if ($start + $num_per_page < $max_value) {
				$display_page = ($start + $num_per_page) > $max_value ? $max_value : ($start + $num_per_page);
				$pageindex .= sprintf($base_link, $display_page, '&gt;&gt;');
			}
			return $pageindex;
	}
	
	function alias($str)
	{				
		if(!$str) return false;
		$utf8 = array(
		'a'=>'á|à|ả|ã|ạ|ă|ắ|ặ|ằ|ẳ|ẵ|â|ấ|ầ|ẩ|ẫ|ậ|Á|À|Ả|Ã|Ạ|Ă|Ắ|Ặ|Ằ|Ẳ|Ẵ|Â|Ấ|Ầ|Ẩ|Ẫ|Ậ',
		'd'=>'đ|Đ',
		'e'=>'é|è|ẻ|ẽ|ẹ|ê|ế|ề|ể|ễ|ệ|É|È|Ẻ|Ẽ|Ẹ|Ê|Ế|Ề|Ể|Ễ|Ệ',
		'i'=>'í|ì|ỉ|ĩ|ị|Í|Ì|Ỉ|Ĩ|Ị',
		'o'=>'ó|ò|ỏ|õ|ọ|ô|ố|ồ|ổ|ỗ|ộ|ơ|ớ|ờ|ở|ỡ|ợ|Ó|Ò|Ỏ|Õ|Ọ|Ô|Ố|Ồ|Ổ|Ỗ|Ộ|Ơ|Ớ|Ờ|Ở|Ỡ|Ợ',
		'u'=>'ú|ù|ủ|ũ|ụ|ư|ứ|ừ|ử|ữ|ự|Ú|Ù|Ủ|Ũ|Ụ|Ư|Ứ|Ừ|Ử|Ữ|Ự',
		'y'=>'ý|ỳ|ỷ|ỹ|ỵ|Ý|Ỳ|Ỷ|Ỹ|Ỵ',
		);
		foreach($utf8 as $ascii=>$uni) $str = preg_replace("/($uni)/i",$ascii,$str);
		return preg_replace("/[^a-zA-Z0-9_\-]+/", "-", $str);
	}
	
	function bodautv($str)
	{				
		if(!$str) return false;
		$utf8 = array(
		'a'=>'á|à|ả|ã|ạ|ă|ắ|ặ|ằ|ẳ|ẵ|â|ấ|ầ|ẩ|ẫ|ậ|Á|À|Ả|Ã|Ạ|Ă|Ắ|Ặ|Ằ|Ẳ|Ẵ|Â|Ấ|Ầ|Ẩ|Ẫ|Ậ',
		'd'=>'đ|Đ',
		'e'=>'é|è|ẻ|ẽ|ẹ|ê|ế|ề|ể|ễ|ệ|É|È|Ẻ|Ẽ|Ẹ|Ê|Ế|Ề|Ể|Ễ|Ệ',
		'i'=>'í|ì|ỉ|ĩ|ị|Í|Ì|Ỉ|Ĩ|Ị',
		'o'=>'ó|ò|ỏ|õ|ọ|ô|ố|ồ|ổ|ỗ|ộ|ơ|ớ|ờ|ở|ỡ|ợ|Ó|Ò|Ỏ|Õ|Ọ|Ô|Ố|Ồ|Ổ|Ỗ|Ộ|Ơ|Ớ|Ờ|Ở|Ỡ|Ợ',
		'u'=>'ú|ù|ủ|ũ|ụ|ư|ứ|ừ|ử|ữ|ự|Ú|Ù|Ủ|Ũ|Ụ|Ư|Ứ|Ừ|Ử|Ữ|Ự',
		'y'=>'ý|ỳ|ỷ|ỹ|ỵ|Ý|Ỳ|Ỷ|Ỹ|Ỵ',
		);
		foreach($utf8 as $ascii=>$uni) $str = preg_replace("/($uni)/i",$ascii,$str);
		return str_replace(' ','',$str);
	}
	
	
	function yummy()
	{		
		return array("@1", "@2", "@3","@4", "@5", "@6","@7", "@8", "@9","@0");

	}
	
	function yummy_()
	{		
		return array("@2", "@4", "@6","@3", "@5", "@7","@8", "@9", "@1","@0");	

	}	
	
	
	function healthy()
	{
		return  array("<div", "</div>", "id","http://", "www", "</","m", "e", "v","i");		
	}
}


	